import json
from pydantic_settings import BaseSettings, SettingsConfigDict
from typing import Dict, Optional, List

class Settings(BaseSettings):
    model_config = SettingsConfigDict(
        env_file=".env",
        env_file_encoding='utf-8',
        extra="ignore"
    )

    APP_NAME: str = "chataigpt-2api"
    APP_VERSION: str = "1.0.5" # <-- 版本号提升
    DESCRIPTION: str = "一个将 chataigpt.net 转换为兼容 OpenAI 格式 API 的高性能代理。"

    API_MASTER_KEY: Optional[str] = None
    
    # chataigpt.net 静态参数
    AJAX_NONCE: str
    POST_ID: int

    # 模型映射 (最终修正版)
    MODEL_TO_BOT_ID_MAP: str = '{"gpt-4": "797", "claude-ai": "818", "grok": "819", "gemini-pro": "820", "deepseek-chat": "821"}'

    API_REQUEST_TIMEOUT: int = 180
    NGINX_PORT: int = 8088

    @property
    def bot_id_map(self) -> Dict[str, str]:
        try:
            return json.loads(self.MODEL_TO_BOT_ID_MAP)
        except json.JSONDecodeError:
            return {}

    @property
    def known_models(self) -> List[str]:
        return list(self.bot_id_map.keys())

settings = Settings()
